#include <stdio.h>

#define STDIN
#define DEBUG

int N;
char array[5001];
short int m[5001][5001];

int min_insert()
{
	int i, j;
#ifdef DEBUG
	for (i = 0; i < N; ++i)
		printf("%c ", array[i]);
	printf("\n");
#endif

	for (i = 0; i < N; ++i)
	{
		m[i][i] = 0;
	}
	for (i = 0; i < N-1; ++i)
	{
		if (array[i] == array[i+1])
			m[i][i+1] = 0;
		else
			m[i][i+1] = 1;
	}

	for (j = 0; j < N; ++j)
	{	
		for (i = j-1; i >= 0; --i)
		{
			int tmp = 5001;
			if (array[i] == array[j])
			{
				m[i][j] = m[i+1][j-1];
				continue;
			}
			tmp = m[i][j-1]+1;
			if (tmp > m[i+1][j]+1)
				tmp = m[i+1][j]+1;
			m[i][j] = tmp;
		}
		
	}

#ifdef DEBUG
	for (i = 0; i < N; ++i)
	{
		for (j = 0; j < N; ++j)
			printf("%d ", m[i][j]);
		printf("\n");
	}
#endif

	printf("%d\n", m[0][N-1]);
	return 0;
}

int main()
{
#ifdef STDIN
	freopen("bin/1159.in", "r", stdin);
#endif

	scanf("%d", &N);
	scanf("%s", array);

	min_insert();
	return 0;

}
